package com.xjgc.msibase.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import com.xjgc.msibase.entity.MsiServerRecordInfo;
import com.xjgc.msibase.mapper.MsiServerRecordInfoMapper;
import com.xjgc.msibase.service.IMsiRealRecordInfoService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 实时接口传输记录 明细
 *
 * @author: 小逗号
 * @date: 2023-9-27
 * @description:
 * @since:
 */
@Slf4j
@Service
public class MsiRealRecordInfoServiceImpl
        extends ServiceImpl<MsiServerRecordInfoMapper, MsiServerRecordInfo>
        implements IMsiRealRecordInfoService {




    @Override
    public void addRecordInfo(String serialNo, Integer nodeCode, String nodeName, String dataTxt, String message) {
        addRecordInfo(serialNo,nodeCode,nodeName,dataTxt,message,new Date());
    }

    @Override
    public void addRecordInfoAsJson(String serialNo, Integer nodeCode, String nodeName, Object object, String message) {
        String dataTxt = JSONObject.toJSONString(object);
        addRecordInfo(serialNo,nodeCode,nodeName,dataTxt,message,new Date());
    }

    @Override
    public void addRecordInfo(String serialNo, Integer nodeCode, String nodeName, List<?> list, String message) {
        addRecordInfoAsJson(serialNo, nodeCode, nodeName, list, message);
    }

    @Override
    public void addRecordInfo(String serialNo, Integer nodeCode, String nodeName, Result<?> result, String message) {
        addRecordInfoAsJson(serialNo, nodeCode, nodeName, result, message);
    }

    @Override
    public void addRecordInfo(String recordId, Integer nodeCode, String nodeName, String dataTxt, String message, Date date){
        MsiServerRecordInfo recordInfo = new MsiServerRecordInfo();
        recordInfo.setRecordId(recordId);
        recordInfo.setNode(nodeCode);
        recordInfo.setNodeName(nodeName);
        recordInfo.setMessage(message);
        recordInfo.setCreateTime(date);
        this.save(recordInfo);
    }
}
